package com.bestv.search.common.service.impl;

import com.bestv.search.common.dao.KeySubjectDao;
import com.bestv.search.common.dataSource.DataSourceKey;
import com.bestv.search.common.model.BizType;
import com.bestv.search.common.model.KeySubject;
import com.bestv.search.common.service.KeySubjectManager;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class KeySubjectManagerImpl implements KeySubjectManager {

    private KeySubjectDao keySubjectDao;

    @Override
    public KeySubject getByTypeName(DataSourceKey key, String type, String name) {
        return keySubjectDao.getByTypeName(type, name);
    }

    @Override
    public KeySubject getById(DataSourceKey key, Long id) {
        return keySubjectDao.get(id);
    }

    @Override
    public KeySubject saveKeySubject(DataSourceKey key, KeySubject ks, BizType bizType) {
        ks.setBizType(bizType);
        return keySubjectDao.saveOrUpdate(ks);
    }

    @Override
    public List<KeySubject> getKeySubjects(DataSourceKey key, int start, int limit) {
        if (start == -1 || limit == -1)
            return keySubjectDao.getAll();
        return keySubjectDao.getKeySubjectsPaging(start, limit);
    }

    @Override
    public Map<String, Integer> findKeyFrequent(DataSourceKey key, String[] keys) {
        return keySubjectDao.findKeyFrequent(keys);
    }

    @Override
    public KeySubject deleteKeySubjectById(DataSourceKey key, Long id) {
        return keySubjectDao.deleteById(id);
    }

    @Override
    public int getKeySubjectCount(DataSourceKey key) {
        return keySubjectDao.getKeySubjectCount();
    }

    @Override
    public int getOnLineKeySubjectsCount(DataSourceKey key) {
        return keySubjectDao.getOnLineKeySubjectsCount();

    }

    @Override
    public List<KeySubject> getOnLineKeySubjects(DataSourceKey key, int start, int limit) {
        return keySubjectDao.getOnLineKeySubjects(start, limit);
    }

    @Override
    public List<KeySubject> getKeySubjectsByUpdateTimeForIndex(DataSourceKey key, Date updateTimeForIndex) {
        return keySubjectDao.getKeySubjectsByUpdateTimeForIndex(updateTimeForIndex);
    }

    public KeySubjectDao getKeySubjectDao() {
        return keySubjectDao;
    }

    public void setKeySubjectDao(KeySubjectDao keySubjectDao) {
        this.keySubjectDao = keySubjectDao;
    }
}
